(function(jQuery) {
	/*
	 * 库位查询放大镜JS插件
	 */

	var gridColMenu_Detail = null;

	$.MagnifierKWUtils = {
		/**
		 * 页面初始化函数
		 */
		init : function() {
			var code = encodeURI($('#condition').val());
			var areaType = encodeURI($('#magnifierKWPage_i_areaType').val());
			var warehouseId = $('#magnifierKWPage_i_warehouseId').val();
			// 创建列表DataGrid
			$('#magnifierKWPage_kw')
					.datagrid(
							{
								url : 'magnifier/getMagnifierKWList.do?catch='
										+ new Date() 
										+ '&code='
										+ code
										+ '&areaType='
										+ areaType
										+ '&warehouseId='
										+ warehouseId +'&Login_SessionId='+sessionId,
								method : 'get',
								title : $.i18n.prop("js.magnifier.title.kw"),
								iconCls : 'icon-large-smartart',
								pagination : true,
								rownumbers : true,
								striped : true,
								pageSize : 10,
								pageList : [10],
								columns : [ [ {
									field : 'ck',
									checkbox:true
								}, {
									field : 'code',
									title : $.i18n.prop("js.magnifier.datagrid.kwdm"),
									width : 100,
									align : 'left'
								}, {
									field : 'typeName',
									title : $.i18n.prop("js.magnifier.datagrid.kwlx"),
									width : 80,
									align : 'left'
								}, {
									field : 'name',
									title : $.i18n.prop("js.magnifier.datagrid.kqmc"),
									width : 145,
									align : 'left'
								}, {
									field : 'lockCount',
									title : $.i18n.prop("js.magnifier.datagrid.pdzt"),
									width : 80,
									align : 'left'
								} ] ],

								onDblClickRow : function(rowIndex, rowData) {
									//向父页面赋值
									if ($('#magnifierKWPage_id').val() != null && $('#magnifierKWPage_id').val().length > 0) {
										$("#" + $('#magnifierKWPage_id').val()).val(rowData.id);
									}
									if ($('#magnifierKWPage_type').val() != null && $('#magnifierKWPage_type').val().length > 0) {
										$("#" + $('#magnifierKWPage_type').val()).val(rowData.type);
									}
									if ($('#magnifierKWPage_typeName').val() != null && $('#magnifierKWPage_typeName').val().length > 0) {
										$("#" + $('#magnifierKWPage_typeName').val()).val(rowData.typeName);
									}
									if ($('#magnifierKWPage_code').val() != null && $('#magnifierKWPage_code').val().length > 0) {
										$("#" + $('#magnifierKWPage_code').val(),
												window.parent.document).searchbox(
												'setValue', rowData.code);
									}
									if ($('#magnifierKWPage_name').val() != null && $('#magnifierKWPage_name').val().length > 0) {
										$("#" + $('#magnifierKWPage_name').val()).val(rowData.name);
									}
									if ($('#magnifierKWPage_lockCount').val() != null && $('#magnifierKWPage_lockCount').val().length > 0) {
										$("#" + $('#magnifierKWPage_lockCount').val()).val(rowData.lockCount);
									}
									//关闭放大镜窗口
									$("#magnifier_window").window('close');
								},
								onLoadError: function(){
									$.LmisUtils.opLoadError();
								}
							});
		},

		/**
		 * 查询
		 */
		search : function() {
			var code = encodeURI($('#condition').val());
			var areaType = encodeURI($('#magnifierKWPage_i_areaType').val());
			var warehouseId = $('#magnifierKWPage_i_warehouseId').val();
			$('#magnifierKWPage_kw')
					.datagrid(
							{
								url : 'magnifier/getMagnifierKWList.do?catch='
										+ new Date() 
										+'&code='
										+ code
										+ '&areaType='
										+ areaType
										+ '&warehouseId='
										+ warehouseId +'&Login_SessionId='+sessionId
							});
		},
		
		/**
		 * 确定
		 */
		ok : function() {
			var selectedKW = $('#magnifierKWPage_kw').datagrid('getSelections');
			var id = "";
			var code = "";
			var type = "";
			var index = 0;
			for (index = 0; index < selectedKW.length; index++) {
				if (index == 0) {
					id = id + selectedKW[index].id;
					code = code + selectedKW[index].code;
					type = type + selectedKW[index].name;
				} else {
					id = id + "," + selectedKW[index].id;
					code = code + "," + selectedKW[index].code;
					type = type + "," + selectedKW[index].name;
				}
			}
			// 向父页面赋值
			if ($('#magnifierKWPage_code').val() != null && $('#magnifierKWPage_code').val().length > 0) {
				$("#" + $('#magnifierKWPage_code').val(),
						window.parent.document).searchbox(
								'setValue', code);
			}
			if ($('#magnifierKWPage_id').val() != null && $('#magnifierKWPage_id').val().length > 0) {
				$("#" + $('#magnifierKWPage_id').val()).val(id);
			}
			if ($('#magnifierKWPage_type').val() != null && $('#magnifierKWPage_type').val().length > 0) {
				$("#" + $('#magnifierKWPage_type').val()).val(type);
			}
			// 关闭放大镜窗口
			$("#magnifier_window").window('close');
		}
	};
})(jQuery);
$.MagnifierKWUtils.init();
